package com.story.api.config;

import com.story.api.moduler.song.interceptor.PlayRecordInterceptor;
import com.story.api.moduler.user.filter.AuthFilter;
import com.story.core.xss.XssFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author Administrator
 * @decription
 * @Date 2017-12-05 14:35
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {

    /**
     * xssFilter注册
     */
    @Bean
    public FilterRegistrationBean xssFilterRegistration() {
        XssFilter xssFilter = new XssFilter();
        FilterRegistrationBean registration = new FilterRegistrationBean(xssFilter);
        registration.addUrlPatterns("/*");
        return registration;
    }

    /**
     * 注册jwt过滤器
     * @return
     */
    @Bean
    public AuthFilter jwtAuthenticationTokenFilter() {
        return new AuthFilter();
    }

    @Bean
    public PlayRecordInterceptor playRecordInterceptor() {
        return new PlayRecordInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(playRecordInterceptor()).addPathPatterns("/child/playAddress","/child/v2/play/address");
    }
}
